package com.lanou.musicbox.fragment.onlinemusic;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.lanou.musicbox.R;
import com.lanou.musicbox.bean.EnterSingersMessage;
import com.lanou.musicbox.utils.VolleySingleton;

/**
 * Created by dllo on 15/10/29.
 */
public class SingersRightFragment extends Fragment {
    private TextView brief;
    private TextView chineseName;
    private TextView alias;
    private TextView englishName;
    private TextView brithData;
    private TextView country;
    private TextView nation;
    private TextView brithPlace;
    private TextView height;
    private TextView weight;
    private TextView bloodType;
    private TextView companyName;
    private TextView school;
    private TextView career;
    private TextView personalLife;
    private TextView awards;
    private TextView entertainmentExperience;
    private View view;
    private String messageurl;
    private VolleySingleton volleySingleton;
    private StringRequest request;
    private EnterSingersMessage  message;
    private EnterSingersMessage.DataEntity singers;
    private ListView listView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.singers_message_item, null);
        brief = (TextView) view.findViewById(R.id.brief);
        chineseName = (TextView) view.findViewById(R.id.chineseName);
        englishName = (TextView) view.findViewById(R.id.englishName);
        brithData = (TextView) view.findViewById(R.id.brithData);
        country = (TextView) view.findViewById(R.id.country);
        nation = (TextView) view.findViewById(R.id.nation);
        brithPlace = (TextView) view.findViewById(R.id.brithPlace);
        height = (TextView) view.findViewById(R.id.height);
        weight = (TextView) view.findViewById(R.id.weight);
        bloodType = (TextView) view.findViewById(R.id.bloodType);
        school = (TextView) view.findViewById(R.id.school);
        career = (TextView) view.findViewById(R.id.career);
        personalLife = (TextView) view.findViewById(R.id.personalLife);
        awards = (TextView) view.findViewById(R.id.awards);
        companyName= (TextView) view.findViewById(R.id.companyName);
        entertainmentExperience = (TextView) view.findViewById(R.id.entertainmentExperience);
        alias= (TextView) view.findViewById(R.id.alias);


        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Bundle bundle = getArguments();
        messageurl = bundle.getString("messageurl");
        Log.i("得到数据",messageurl+" ");

        initdata();
    }

    private void initdata() {
        volleySingleton=VolleySingleton.getInstance(getActivity());
        request =new StringRequest(messageurl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson =new Gson();
                message =gson.fromJson(response,EnterSingersMessage.class);
                if (message != null&&message.getData()!=null) {
                    singers=message.getData();
                }
                getmessage(singers);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        volleySingleton.addQueue(request);
    }


    private void getmessage(EnterSingersMessage.DataEntity singers){
        brief.setText(singers.getBrief());
        chineseName.setText(singers.getChineseName());
        companyName.setText(singers.getCompanyName());
        englishName.setText(singers.getEnglishName());
        brithData.setText(singers.getBirthDate());
        country.setText(singers.getCountry());
        nation.setText(singers.getNation());
        brithPlace.setText(singers.getBirthDate());
        height.setText(singers.getHeight());
        weight.setText(singers.getWeight());
        bloodType.setText(singers.getBloodType());
        school.setText(singers.getSchool());
        career.setText(singers.getCareer());
        personalLife.setText(singers.getPersonalLife());
        entertainmentExperience.setText(singers.getEntertainmentExperience());
        awards.setText(singers.getAwards());
        alias.setText(singers.getAlias().get(0));
    }
}
